package com.springboot.chatroom.controller;


import com.springboot.chatroom.model.Message;
import com.springboot.chatroom.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description :
 * User: jiume
 * Date: 2025-04-16
 * Time: 18:38
 */
@Slf4j
@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @RequestMapping(value = "/getHistoryMessages",method = RequestMethod.GET)
    public Object getHistoryMessages(Integer sessionId) {
        // 验证参数是否合法
        if (sessionId == null || sessionId <= 0) {
            log.info("[getHistoryMessages] sessionId 不合法...");
            return new ArrayList<Message>();
        }
        return messageService.getHistoryMessageBySessionId(sessionId);
    }
}
